<template>
    <div>
        <rui-page :defines="defines">
            <rui-query :label-width="180"
                       ref="searchForm"
                       :query="queryData"
                       :query-rows="searchFormOptions"
                       :more-rows="searchFormOptionsRows"
            >
            </rui-query>
            <rui-table
                :defineId="'upcomeTasks'"
                :fixedLeft="['applyNo']"
                :showIndex="false"
                :select="false"
                :columns="upcomeTasksColumns"
                :slots="[{key:'applyNo',slot:'applyNo'}]"
                @loadDatas="queryData"
                ref-query="searchForm"
                ref="upcomeTasksTable"
            >
                <template slot="applyNo" slot-scope="{ row }">
                    <div>
                        <a @click="edit('write',row)">{{row.applyNo}}</a>
                    </div>
                </template>
            </rui-table>
        </rui-page>
    </div>
</template>
<script>
    import upcomeTasks from "./define/upcome-tasks-define";
    import {findUpcomeTasksList} from "_p/basic/api/contract/common/upcome-tasks/upcome-tasks";

    export default {
        data() {
            return {
                searchFormOptions: [
                    {
                        defineId: "upcomeTasks",
                        fields: ["applyNo", "contractNo", "custName"]
                    }
                ],
                searchFormOptionsRows: [
                    {
                        defineId: "upcomeTasks",
                        fields: ["processStatus", "businessSource", "contractStatus"],
                    }
                ],
                upcomeTasksColumns: [
                    'applyNo', 'contractNo', 'caseNo', 'contractStatus', 'processStatus', 'custName', 'certNo',
                    'createTime', 'businessSource', 'contractBusiness'],
                selectCount: 0,
            };
        },
        computed: {
            defines() {
                return [
                    {
                        id: "upcomeTasks",
                        fields: upcomeTasks
                    }
                ];
            }
        },
        activated() {
            this.refresh();
        },
        methods: {
            queryData(queryData) {
                findUpcomeTasksList(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.upcomeTasksTable.updateTableData(records, total);
                    }
                });
            },
            refresh() {
                this.$refs['upcomeTasksTable'].reloadData();
                this.clearSelectAll();
            },
            clearSelectAll() {
                this.$refs.upcomeTasksTable.getTable().selectAll(false);
            },
            edit(type, contract) {
                contract.editFlag = true,
                    this.afs.newTab(
                        this,
                        contract.businessUrl,
                        "合同待办任务详情",
                        "ios-add",
                        contract,
                        "contract-" + contract.id,
                        [],
                        true
                    );
            }
        }
    };
</script>
